from openpyxl import Workbook


def export_list_dicts(data):
    wb = Workbook()
    ws = wb.active
    if isinstance(data, list) and data:
        headers = list(data[0].keys())
        ws.append(headers)
        for row in data:
            ws.append([row.get(h) for h in headers])
    else:
        ws.append(['message'])
        ws.append(['no data'])
    from io import BytesIO
    buf = BytesIO()
    wb.save(buf)
    return buf.getvalue(), 'analyzer.xlsx'
